/*
 * MIT License
 *
 * Copyright (c) 2021-2022 yangrunkang
 *
 * Author: yangrunkang
 * Email: yangrunkang53@gmail.com
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.upupor.framework.config;

import com.upupor.framework.utils.SystemUtil;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;

import java.util.List;

import static com.upupor.framework.utils.CcUtils.checkEnvIsDev;


/**
 * @author Yang Runkang (cruise)
 * @date 2021年12月12日 22:37
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "upupor")
public class UpuporConfig {
    private Pool pool;
    private Thumbnails thumbnails;
    private Email email;
    private String website;
    private Integer adSwitch;
    private String adSwitchRight;
    private String analyzeSwitch;
    private Oss oss;
    // 静态文件地址
    private String ossStatic;
    private String env;
    /**
     * 不用校验是否登录的url
     */
    private List<String> interfaceWhiteUrlList;
    /**
     * 页面需要校验登录的url
     */
    private List<String> pageCheckUrlList;
    private GoogleAd googleAd;

    private String googleTagId;
    private String googleGa4;


    public String getOssStatic() {
        // 如果没有配置oss地址,则使用本地地址
        if (StringUtils.isEmpty(ossStatic) && checkEnvIsDev()) {
            return String.format("http://%s:%s", SystemUtil.getHostAddress(), serverPort);
        }
        return ossStatic;
    }

    @Value("${server.port}")
    private Integer serverPort;


}
